﻿using System;
using System.Diagnostics;

namespace AruaRose
{
    public static class Charachter
    {
        public static string Name { get; set; }
        public static Info Info { get; set; }
        public static Status Status { get; set; }
        public static Process Process { get; set; }

        public static bool Initialize(string processName)
        {
            Process[] processes = Process.GetProcessesByName(processName);
            if (processes.Length < 1) return false;

            ProcessMemoryReader.ReadProcess = processes[0];
            ProcessMemoryReader.OpenProcess();
            Process = processes[0];

            return true;
        }
        public static void Fill()
        {
            if (Process == null) throw new Exception("Process could not be found.");
            
            IntPtr address = Process.MainModule.BaseAddress + HexToDec("2936A8");
            byte[] memoryvalue = ProcessMemoryReader.ReadProcessMemory(address, 4);
            int pointer = BitConverter.ToInt32(memoryvalue, 0);

            Info.HP.Current = BitConverter.ToUInt16(ProcessMemoryReader.ReadProcessMemory((IntPtr)pointer + HexToDec("564"), 2), 0);
            Info.MP.Current = BitConverter.ToUInt16(ProcessMemoryReader.ReadProcessMemory((IntPtr)pointer + HexToDec("566"), 2), 0);
            Info.Experience.Current = BitConverter.ToInt32(ProcessMemoryReader.ReadProcessMemory((IntPtr)pointer + HexToDec("568"), 4), 0);
        }
        private static int HexToDec(string hex)
        {
            return Int32.Parse(hex, System.Globalization.NumberStyles.HexNumber);
        }
    }

    public class Health
    {
        public int Current { get; set; }
        public int Total { get; set; }
    }
    public class Mana : Health
    {
    }
    public class Experience : Health
    {
        public int Level { get; set; }
    }

    public class Info
    {
        public Health HP { get; set; }
        public Mana MP { get; set; }
        public Experience Experience { get; set; }
    }

    public class Status
    {
        public int TargetId { get; set; }
        public int AggroId { get; set; }
        public int ActionId { get; set; }
    }
}
